package Demo1;

//定义键盘类
public class Computer {

    //普通方法
    public void powerOn(){

        System.out.println("打开电脑....");
    }
    public void powerOff(){
        System.out.println("关闭电脑....");
    }

    //使用接口
    public void useIUsb(IUsb iUsb){

        //向下转型
        if(iUsb instanceof Mouse){
            Mouse mouse = (Mouse) iUsb;

         //调用方法
             mouse.openDevice();
            mouse.click();
            mouse.closeDevice();
        }else if(iUsb instanceof KeyBoard){
            KeyBoard keyBoard = (KeyBoard) iUsb;

            //调用方法
            keyBoard.openDevice();
            keyBoard.use();
            keyBoard.closeDevice();
        }
    }

}
